import { HttpParams, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';

export function GET(url: string): Function {
    return function (target: any, key: string, descriptor: PropertyDescriptor) {
        descriptor.value = function (params?: HttpParams): Observable<any> {
            return this.http.get(url, {
                params: params
            });
        };
    };
}

export function POST(url: string): Function {
    return function (target: any, key: string, descriptor: PropertyDescriptor): void {
        descriptor.value = function (body): Observable<any> {
            const headers = new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8');
            return this.http.post(url, body, {
                headers: headers
            });
        };
    };
}
